<?php
include("../conn/conn.php");
$title=$_POST[title];
$content=$_POST[EditorDefault];
//$time=date("Y-m-j H:i:s");


function getname($exname){
   $dir = "../upimages/";
   $i=1;
   if(!is_dir($dir)){
      mkdir($dir,0777);
   }

	  $name=time().".".$exname;
   return $dir.$name;
}

$exname=strtolower(substr($_FILES['upfile']['name'],(strrpos($_FILES['upfile']['name'],'.')+1)));
$uploadfile = getname($exname);
move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile);
if(trim($_FILES['upfile']['name']!=""))
 { 
  $uploadfile="admin/".substr($uploadfile,3);
}
else
 {
  $uploadfile="";
 }


mysql_query("insert into tb_banner(title,content,image)values('$title','$content','$uploadfile')",$conn);
echo "<script>alert('添加广告成功!');window.location.href='../adminbanner.php';</script>";
?>
